package com.scau.phradmin.business.contents.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.scau.phradmin.common.util.PageDTO;

import com.scau.phradmin.domain.entity.News;
import com.scau.phradmin.domain.mapper.NewsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * @author chenyunan
 * @date 2018/8/9 11:47
 */

@Service
public class NewsServiceImpl {

    @Autowired
    private NewsMapper newsMapper;
    /**
     * 查询所有新闻信息
     * @param pages
     * @return
     */
    public PageDTO<News> SelectAll(int pages){
        Page page=null;
        if(pages>0) {
            page=new Page(pages,10);
        }
        else{
            page=new Page(1,10);
        }
        List<News> list=newsMapper.queryAll(page);
        return PageDTO.valueOf(list,page);
    }
    public boolean Add(News news){
        return newsMapper.insert(news) > 0;
    }
    public Object SelectById(@RequestParam("newsId") Integer id){
        return newsMapper.queryOne(id);
    }
    public boolean update(News news){
        return newsMapper.updateById(news) > 0;
    }


}
